package oj;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

public class S {

    public static void main(String[] args) {
        Map<String, String> set = new LinkedHashMap<>();
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        while (count-- > 0) {
            String next = in.next();
            set.put(next, next);
        }

        int total = 0;
        count = in.nextInt();
        while (count-- > 0) {
            if (total >= 50) {
                return;
            }
            String next = in.next();
            System.out.println(next);
            total++;
            boolean bo = true;
            for (Map.Entry<String, String> entry : set.entrySet()) {
                if (total >= 50) {
                    return;
                }
                if (entry.getKey().indexOf(next) >= 0 && !next.equals(entry.getKey())) {
                    System.out.println(entry.getKey());
                    total++;
                    bo = false;
                }
            }
            if (bo){
                set.put(next, next);
            }
        }
    }
}
